package ytmc;

import ytmc.mainWindow.MainWindowController;
import java.util.HashMap;
import javax.swing.UIManager;
import ytmc.about.AboutView;
import ytmc.converter.ConverterController;
import ytmc.downloader.DownloaderController;
import ytmc.mainWindow.MainWindowView;
import ytmc.setup.SetupController;
import ytmc.uploader.UploaderController;
import ytmc.videoManager.VideoManagerController;


/**
 *
 * @author Kicok
 */
public class Bootstrap
{
    private static HashMap<String, Controller> controllers;

    public static void main( String args[] )
    {
        setOSLookAndFeel();

        initControllers();
        buildViewTree();

        showMainWindow();
    }



    private static void setOSLookAndFeel()
    {
        try
        {
            UIManager.setLookAndFeel( "com.sun.java.swing.plaf.windows.WindowsLookAndFeel" );
        }
        catch( Exception e )
        {
            System.out.println( "DEBUG: Nie udało się ustawić Windowsowego wyglądu kontrolek." );
            System.out.println( e );
        }
    }

    private static void initControllers()
    {
        controllers = new HashMap<String, Controller>();
        controllers.put( "MainWindow", new MainWindowController() );
        controllers.put( "Downloader", new DownloaderController() );
        controllers.put( "Uploader", new UploaderController() );
        controllers.put( "VideoManager", new VideoManagerController() );
        controllers.put( "Converter", new ConverterController() );
        controllers.put( "Setup", new SetupController() );
    }

    private static void buildViewTree()
    {
        MainWindowView view = (MainWindowView)controllers.get( "MainWindow" ).getView();
        view.addChild( "Pobieranie", "/assets/down24.png", (PanelView)controllers.get( "Downloader" ).getView() );
        view.addChild( "Wysyłanie", "/assets/up24.png", (PanelView)controllers.get( "Uploader" ).getView() );
        view.addChild( "Moje konto", "/assets/my-account24.png", (PanelView)controllers.get( "VideoManager" ).getView() );
        view.addChild( "Konwertowanie", "/assets/convert24.png",(PanelView)controllers.get( "Converter" ).getView() );
        view.addChild( "Ustawienia", "/assets/config24.png", (PanelView)controllers.get( "Setup" ).getView() );
        view.addChild( "O Programie", "/assets/about24.png", new AboutView() );
    }

    private static void showMainWindow()
    {
        final MainWindowView mainWindow = (MainWindowView)controllers.get( "MainWindow" ).getView();
        java.awt.EventQueue.invokeLater( new Runnable()
        {
            @Override
            public void run()
            {
                mainWindow.setVisible( true );
            }
        } );
    }
}